﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;

namespace OrangePrj
{
    public partial class FormSetDepends : Form
    {
        public bool set = false;
        public ArrayList depInd_new;
        private ArrayList depInd_old;
        public ArrayList depWorks;
        private ArrayList worklist;
        int count;
        int ind;

        public FormSetDepends(ArrayList worklist, ArrayList depInd_old, int index, int x, int y, int width, int height)
        {
            InitializeComponent();
            this.SetBounds(x, y, width, height);
            this.depInd_old = depInd_old;
            this.depInd_new = new ArrayList();
            this.depWorks = new ArrayList();
            this.worklist = worklist;
            count = worklist.Count;
            this.ind = index;
            Work w = new Work();
            w = (Work)worklist[index];

            //задание внешнего вида окна зависимостей
            labelWorkName.Text = "Зависимости для " + '"' + w.Name+ '"';
            checkedListBoxSetDepends.Height = this.Height;
            checkedListBoxSetDepends.Width = this.Width;
             
            //вывод работ
            for (int i = 0; i < count; i++)
            {
                if (i != index)
                {
                    w = (Work)worklist[i];
                    checkedListBoxSetDepends.Items.Add((i + 1).ToString() + ") " + w.Name);
                }
            }

            foreach (int i in depInd_old)
            {
                if (i<ind)
                    checkedListBoxSetDepends.SetItemChecked(i, true);
                else
                    checkedListBoxSetDepends.SetItemChecked(i-1, true);
            }
        }

        private void buttonSet_Click(object sender, EventArgs e)
        {
            for (int i=0; i<ind; i++)
            {
                if (checkedListBoxSetDepends.GetItemChecked(i) == true)
                {
                    depInd_new.Add(i);
                    depWorks.Add(worklist[i]);
                }
            }
            for (int i = ind; i < count-1; i++)
            {
                if (checkedListBoxSetDepends.GetItemChecked(i) == true)
                {
                    depInd_new.Add(i + 1);
                    depWorks.Add(worklist[i+1]);
                }
            }
            set = true;
        }
    }
}
